package com.allwees.bs.module.core.sender.rest;

import com.allwees.bs.core.modelbase.vo.R;
import com.allwees.bs.module.core.rest.BaseApi;
import com.allwees.bs.module.core.sender.req.SendSmsReq;
import com.allwees.core.common.util.http.RequestUtil;
import com.allwees.sender.sms.SendResult;
import com.allwees.sender.sms.SmsSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 短信发送API
 *
 * @author yangylsky
 * @since 2020-01-02
 *
 */
@RestController
@RequestMapping("/backstage/api/common/sms")
public class SmsApi extends BaseApi {
    @Autowired
    private SmsSender smsSender;

    @PostMapping("/send_sms")
    public R auditStatus(@RequestBody SendSmsReq req, HttpServletRequest request) {
    	SendResult sendResult = smsSender.sendSms(req.getBsType(), req.getMobile(), RequestUtil.getIpFromRequest(request));
        return sendResult.isSuccess() ? R.ok(sendResult.getMsg()) : R.error(sendResult.getMsg());
    }
}
